package com.yykj.order.center.server.controller;

import com.yykj.common.vo.ResultVO;
import com.yykj.order.center.client.dto.ConsultationDoctorDto;
import com.yykj.order.center.client.dto.ConsultationDoctorListDto;
import com.yykj.order.center.client.dto.ConsultationListDto;
import com.yykj.order.center.client.dto.base.PaginationListDto;
import com.yykj.order.center.client.form.consultation.ConsultationAdminDoctorListForm;
import com.yykj.order.center.client.form.consultation.ConsultationAdminDoctorReviewForm;
import com.yykj.order.center.client.form.consultation.ConsultationAdminListForm;
import com.yykj.order.center.client.form.consultation.ConsultationAdminReviewForm;
import com.yykj.order.center.server.service.ConsultationAdminService;
import com.yykj.order.center.server.service.ConsultationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 在线会诊 订单
 */
@RestController
@RequestMapping("/admin/consultation")
@Api(tags = "在线会诊 后台管理相关接口")
public class ConsultationAdminController {

    @Autowired
    ConsultationAdminService consultationAdminService;

    @Autowired
    ConsultationService consultationService;

    //TODO doctorId 需要从token里拿

    @PostMapping("/list")
    @ApiOperation(value = "会诊列表")
    public ResultVO<PaginationListDto<ConsultationListDto>> list(@RequestBody @Valid ConsultationAdminListForm consultationAdminListForm) {
        return ResultVO.success(consultationAdminService.list(consultationAdminListForm));
    }

    @PostMapping("/doctor/list")
    @ApiOperation(value = "与会医生列表")
    public ResultVO<PaginationListDto<ConsultationDoctorListDto>> doctorList(@RequestBody @Valid ConsultationAdminDoctorListForm consultationAdminDoctorListForm) {
        return ResultVO.success(consultationAdminService.doctorList(consultationAdminDoctorListForm));
    }

    @GetMapping("/info/{consultationId}")
    @ApiOperation(value = "会诊详情")
    public ResultVO<ConsultationListDto> info(@PathVariable(value = "consultationId", required = true) String consultationId) {
        return ResultVO.success(consultationService.info(consultationId));
    }

    @PostMapping("/review")
    @ApiOperation(value = "审核会诊")
    public ResultVO review(@RequestBody @Valid ConsultationAdminReviewForm consultationAdminReviewForm) {
        consultationAdminService.review(consultationAdminReviewForm);
        return ResultVO.success();
    }

    @PostMapping("/doctor/review")
    @ApiOperation(value = "审核与会医生")
    public ResultVO doctorReview(@RequestBody @Valid ConsultationAdminDoctorReviewForm consultationAdminDoctorReviewForm) {
        consultationAdminService.doctorReview(consultationAdminDoctorReviewForm);
        return ResultVO.success();
    }

    @PostMapping("/doctor/chargeback/review")
    @ApiOperation(value = "审核申请医生退单")
    public ResultVO doctorChargebackReview(@RequestBody @Valid ConsultationAdminDoctorReviewForm consultationAdminDoctorReviewForm) {
        consultationAdminService.doctorChargebackReview(consultationAdminDoctorReviewForm);
        return ResultVO.success();
    }
}
